package com.itheima.admin.controller;

import com.itheima.Result;
import com.itheima.admin.dto.ModuleDto;
import com.itheima.admin.pojo.Module;
import com.itheima.admin.service.IModuleService;
import com.itheima.admin.vo.ModuleVo;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/module")
@CrossOrigin
public class ModuleController {

    @Autowired
    private IModuleService moduleService;

    @ApiOperation("查找所有模块")
    @GetMapping("/all")
    public List<ModuleVo> queryAll(){
        return moduleService.queryAll();
    }

    @PostMapping("/add")
    @ApiOperation("添加模块")
    public Result addModule(@RequestBody ModuleDto moduleDto){
        boolean flag = moduleService.addModule(moduleDto);
        return new Result(flag,flag?"添加模块成功":"添加模块失败",null);
    }

    @DeleteMapping("/{id}")
    @ApiOperation("删除模块")
    public Result deleteRoleModules(@PathVariable("id") String id){
        boolean result = moduleService.deleteRoleModule(id);
        return new Result(result,result?"删除模块成功":"删除模块失败",null);
    }

}
